package cn.tedu.cwfw.client.controller;

import cn.tedu.cwfw.base.response.JsonResult;
import cn.tedu.cwfw.client.pojo.dto.ClientLoginParam;
import cn.tedu.cwfw.client.pojo.dto.ClientQuery;
import cn.tedu.cwfw.client.pojo.dto.ClientSaveParam;
import cn.tedu.cwfw.client.pojo.vo.ClientVO;
import cn.tedu.cwfw.client.service.ClientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/cwfw/client")
public class ClientController {
    @Autowired
    ClientService clientService;
    @PostMapping("login")
    public JsonResult login(@RequestBody ClientLoginParam clientLoginParam){
        log.debug("用户登录：userLoginParam={}",clientLoginParam);
        ClientVO clientVO = clientService.login(clientLoginParam);
        return JsonResult.ok(clientVO);
    }
    @PostMapping("save")
    public JsonResult saveClient(@RequestBody ClientSaveParam clientSaveParam){
        log.debug("保存用户信息：userSaveParam={}",clientSaveParam);
        clientService.saveClient(clientSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("/delete/{clientId}")
    public JsonResult deleteClient(@PathVariable Long clientId){
        log.debug("删除用户：userId={}",clientId);
        clientService.deleteClient(clientId);
        return JsonResult.ok();
    }
    @GetMapping("select")
    public JsonResult selectClient(ClientQuery clientQuery){
        log.debug("查询用户：userQuery={}",clientQuery);
        List<ClientVO> list = clientService.selectClient(clientQuery);
        return JsonResult.ok(list);
    }
}
